<?php
namespace Home\Controller;

use Common\Controller\UserBaseController;

/**
 * 首页控制器
 */
//  {"account":{"balance":1950,"betting":50,"bonus":0,"freeze":0},"ids":["170406605884222","170406605884223","170406605884224","170406605884225","170406605884226"],"odds":["1.79","1.988","1.988","1.988","1.988"],"status":0}   bet返回

//{"account":{"balance":1990,"betting":10,"bonus":0,"freeze":0},"status":2} 封盘返回数据  封盘后不能下单还没有做

class BetController extends UserBaseController
{
    /**
     * 首页
     */
    public function bet()
    {

        header('Content-type:text/json;');
        $type_array      = S('type_array');
        $member_info_old = M('member')->where('member_id=' . $_SESSION['member_id'])->find();

        $data1    = file_get_contents('php://input');
        $data     = json_decode($data1, true);
        $c_type   = $data['lottery'];
        $callback = array();
        switch ($c_type) {
            //幸运飞艇
            case 'XYFT': //幸运飞艇 彩种id 5
                $c_id   = 5;
                $c_name = '幸运飞艇';

                $open_time = S('op_time_5');

                if (empty($open_time)) {
                    $condition['c_id'] = 5;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_5', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }

                break;
            //北京PK10
            case 'BJPK10': //北京PK10 彩种id 4
                $c_id   = 4;
                $c_name = '北京PK10';

                $open_time = S('op_time_4');

                if (empty($open_time)) {
                    $condition['c_id'] = 4;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_4', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //重庆时时彩
            case 'CQSSC': //重庆时时彩 彩种id 1
                $c_id   = 1;
                $c_name = '重庆时时彩';

                $open_time = S('op_time_1');

                if (empty($open_time)) {
                    $condition['c_id'] = 1;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_1', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //新疆时时彩
            case 'XJSSC': //新疆时时彩 彩种id 2
                $c_id   = 2;
                $c_name = '新疆时时彩';

                $open_time = S('op_time_2');

                if (empty($open_time)) {
                    $condition['c_id'] = 2;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_2', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //天津时时彩
            case 'TJSSC': //天津时时彩 彩种id 3
                $c_id   = 3;
                $c_name = '天津时时彩';

                $open_time = S('op_time_3');

                if (empty($open_time)) {
                    $condition['c_id'] = 3;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_3', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //重庆幸运农场
            case 'XYNC': //重庆幸运农场 彩种id 8
                $c_id   = 8;
                $c_name = '重庆幸运农场';

                $open_time = S('op_time_8');

                if (empty($open_time)) {
                    $condition['c_id'] = 8;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_8', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //广东快乐十分
            case 'GDKLSF': //广东快乐十分 彩种id 6
                $c_id   = 6;
                $c_name = '广东快乐十分';

                $open_time = S('op_time_6');

                if (empty($open_time)) {
                    $condition['c_id'] = 6;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_6', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //广西快三
            case 'GXK3': //广西快三 彩种id 7
                $c_id   = 7;
                $c_name = '广西快三';

                $open_time = S('op_time_7');

                if (empty($open_time)) {
                    $condition['c_id'] = 7;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_7', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //河北快三
            case 'HEBK3': //河北快三 彩种id 18
                $c_id   = 18;
                $c_name = '河北快三';

                $open_time = S('op_time_18');

                if (empty($open_time)) {
                    $condition['c_id'] = 18;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_18', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //湖北快三
            case 'HUBK3': //湖北快三 彩种id 19
                $c_id   = 19;
                $c_name = '湖北快三';

                $open_time = S('op_time_19');

                if (empty($open_time)) {
                    $condition['c_id'] = 19;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_19', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //江苏快三
            case 'JSK3': //江苏快三 彩种id 20
                $c_id   = 20;
                $c_name = '江苏快三';

                $open_time = S('op_time_20');

                if (empty($open_time)) {
                    $condition['c_id'] = 20;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_20', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //PC蛋蛋
            case 'PCEGG': //PC蛋蛋 彩种id 11
                $c_id   = 11;
                $c_name = 'PC蛋蛋';

                $open_time = S('op_time_11');

                if (empty($open_time)) {
                    $condition['c_id'] = 11;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_11', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //北京快8
            case 'BJKL8': //北京快8 彩种id 9
                $c_id   = 9;
                $c_name = '北京快8';

                $open_time = S('op_time_9');

                if (empty($open_time)) {
                    $condition['c_id'] = 9;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_9', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //台湾宾果
            case 'TWBG': //台湾宾果 彩种id 22
                $c_id   = 22;
                $c_name = '台湾宾果';

                $open_time = S('op_time_22');

                if (empty($open_time)) {
                    $condition['c_id'] = 22;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_22', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //广西快乐十分
            case 'GXKLSF': //广西快乐十分 彩种id 10
                $c_id   = 10;
                $c_name = '广西快乐十分';

                $open_time = S('op_time_10');

                if (empty($open_time)) {
                    $condition['c_id'] = 10;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_10', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //六合彩
            case 'HK6': //六合彩 彩种id 12
                $c_id   = 12;
                $c_name = '六合彩';

                break;
            //QQ分分彩
            case 'FFC': //QQ分分彩 彩种id 16
                $c_id   = 13;
                $c_name = '分分彩';

                // $percentage=0;
                $open_time = S('op_time_13');

                if (empty($open_time)) {
                    $open_time = include APP_PATH . 'Common/Common/ffctime.php';

                    S('op_time_13', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //加拿大
            case 'JNDKL8': //加拿大快乐8
                $c_id   = 15;
                $c_name = '加拿大快乐8';

                //  $percentage=0;
                $open_time = S('op_time_15');

                if (empty($open_time)) {
                    $condition['c_id'] = 15;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_15', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;
            //QQ分分彩
            case 'QQFFC': //QQ分分彩 彩种id 16
                $c_id   = 16;
                $c_name = 'QQ分分彩';

                $open_time = S('op_time_16');

                if (empty($open_time)) {
                    $open_time = include APP_PATH . 'Common/Common/ffctime.php';

                    S('op_time_16', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;

            case 'TXFFC': //腾讯分分彩 彩种id 17
                $c_id   = 17;
                $c_name = '腾讯分分彩';

                $open_time = S('op_time_17');

                if (empty($open_time)) {
                    $open_time = include APP_PATH . 'Common/Common/ffctime.php';

                    S('op_time_17', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;

            //台湾五分
            case 'TWWF': //台湾五分 彩种id 23
                $c_id   = 23;
                $c_name = '台湾五分';

                $open_time = S('op_time_23');

                if (empty($open_time)) {
                    $condition['c_id'] = 23;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_23', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;

            //加拿大3.5
            case 'JND': //加拿大3.5 彩种id 24
                $c_id   = 24;
                $c_name = '加拿大3.5';

                $open_time = S('op_time_24');

                if (empty($open_time)) {
                    $condition['c_id'] = 24;
                    $op_time           = M('open_time')->where($condition)->getField('data');
                    $open_time         = unserialize($op_time);
                    // print_r($open_time);exit;
                    S('op_time_24', $open_time);
                }
                $day1 = date('Ymd');
                foreach ($open_time as $k => $v) {
                    $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                    $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                    $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                    $n_time      = time();
                    if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                        $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                        $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                        $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                        if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                            $data['status'] = 1;
                        } else {
                            $data['status']                 = 2;
                            $callback['account']['balance'] = (float) $member_info_old['member_money'];
                            $callback['account']['betting'] = 0;
                            $callback['account']['bonus']   = 0;
                            $callback['account']['freeze']  = $member_info_old['member_f_money'];
                            $callback['status']             = 2;
                            echo json_encode($callback);exit(0);
                        }
                    }

                }
                break;

            default:
                break;
        }

        $time          = time();
        $sum           = 0;
        $error['code'] = '下注失败';

        foreach ($data['bets'] as $k => $v) {
            $i = $k + 1;

            $insert_data[$k]['c_id']   = $c_id;
            $insert_data[$k]['c_name'] = $data['lottery'];
            $insert_data[$k]['c_no']   = $data['drawNumber'];
            $insert_data[$k]['w_type'] = $v['game'];
            if ($data['lottery'] == 'HK6') {

                $hk_type_array = include APP_PATH . 'Common/Common/HK6.php';

                //print_r($hk_type_array);exit;
                if ($v['game'] == 'ZM' || $v['game'] == 'TMA' || $v['game'] == 'TMB' || $v['game'] == 'ZMT1' || $v['game'] == 'ZMT2' || $v['game'] == 'ZMT3' || $v['game'] == 'ZMT4' || $v['game'] == 'ZMT5' || $v['game'] == 'ZMT6') {
                    $insert_data[$k]['w_name'] = $hk_type_array[$v['game']];
                    $insert_data[$k]['t_name'] = $hk_type_array[$v['contents']];
                } elseif ($v['game'] == 'HX' || $v['game'] == 'LM3Z2' || $v['game'] == 'LM3QZ' || $v['game'] == 'LM2QZ' || $v['game'] == 'LM2ZT' || $v['game'] == 'LMTC' || $v['game'] == 'LM4QZ' || $v['game'] == 'ZXBZ') {
                    //
                    $insert_data[$k]['w_name'] = $hk_type_array[$v['game']];
                    $insert_data[$k]['t_name'] = '';
                } else {
                    $insert_data[$k]['w_name'] = $hk_type_array[$v['game']]['text'];
                    $insert_data[$k]['t_name'] = $hk_type_array[$v['game']][$v['contents']];
                }

            } else {

                if ($v['game'] == 'ZM' || $v['game'] == 'B1' || $v['game'] == 'B2' || $v['game'] == 'B3' || $v['game'] == 'B4' || $v['game'] == 'B5' || $v['game'] == 'B6' || $v['game'] == 'B7' || $v['game'] == 'B8' || $v['game'] == 'B9' || $v['game'] == 'B10' || $v['game'] == 'GYH' || $v['game'] == 'HZ') {
                    $insert_data[$k]['w_name'] = $type_array[$v['game']];
                    $insert_data[$k]['t_name'] = $type_array[$v['contents']];
                } elseif ($v['game'] == 'LM2' || $v['game'] == 'LM22' || $v['game'] == 'LM3' || $v['game'] == 'LM33' || $v['game'] == 'LM4' || $v['game'] == 'LM5' || $v['game'] == 'QS' || $v['game'] == 'DS' || $v['game'] == 'BZ' || $v['game'] == 'TMB3' || $v['game'] == 'SB') {
                    if ($c_type == 'PCEGG' && $v['game'] == 'DS') {
                        $insert_data[$k]['w_name'] = $type_array['PDS']['text'];
                        $insert_data[$k]['t_name'] = $type_array['PDS'][$v['contents']];
                    } elseif ($v['game'] == 'SB') {
                        $insert_data[$k]['w_name'] = $type_array['SB'][$v['contents']];
                        $insert_data[$k]['t_name'] = '';
                    } else {
                        $insert_data[$k]['w_name'] = $type_array[$v['game']];
                        $insert_data[$k]['t_name'] = '';
                    }
                } else {

                    //if($c_type=='BJKL8'){
                    //                    $insert_data[$k]['w_name']=$type_array['BDXDS']['text'];
                    //                    $insert_data[$k]['t_name']=$type_array['BDXDS'][$v['contents']];
                    //                    }else{
                    $insert_data[$k]['w_name'] = $type_array[$v['game']]['text'];
                    $insert_data[$k]['t_name'] = $type_array[$v['game']][$v['contents']];
                    // }

                }
            }
            $percentage                = M('rebate_setting')->where('c_id=' . $c_id . ' and status=1')->getField('percentage');
            $insert_data[$k]['t_type'] = $v['contents'];
            if ($v['multiple'] > 0) {
                $insert_data[$k]['money'] = $v['amount'] * $v['multiple']; //复式下注
            } else {
                $insert_data[$k]['money'] = $v['amount'];
            }
            $insert_data[$k]['odds']     = $v['odds'];
            $insert_data[$k]['order_sn'] = build_order_no() + $i; //获取订单号
            $insert_data[$k]['add_time'] = $time;
            $insert_data[$k]['m_id']     = $_SESSION['member_id'];
            if ($percentage) {
                $insert_data[$k]['rebate'] = (float) $percentage * $v['amount'] / 100;
            }
            $insert_data[$k]['pan'] = $member_info_old['pan'];

            $sum                = $sum + $insert_data[$k]['money'];
            $callback['ids'][]  = "" . $insert_data[$k]['order_sn'] . "";
            $callback['odds'][] = "" . $v['odds'] . "";
        }
        $member_info = M('member')->where('member_id=' . $_SESSION['member_id'])->find();
        //现在的赔率
        // $odds=M('lottery_odds')->where('c_id='.$c_id.' and w_id')
        $odds = S('odds_' . $c_type);

        //连码情况下的赔率
        if (substr($v['game'], 0, 2) == 'LM' || $v['game'] == 'TMB3') {
            $odds = $odds[$v['game'] . '_0'];
        } elseif ($v['game'] == 'LX') {
            //连肖
            $lx_content = $v['contents'];
            $lx_content = explode(',', $lx_content);
            foreach ($lx_content as $kk => $vv) {
                $lx_content[$kk] = $odds[$v['game'] . '_' . $vv];
            }
            sort($lx_content);
            $odds = $lx_content[0];
        } elseif (substr($v['game'], 0, 2) == 'LW') {
            //连尾
            $lw_content = $v['contents'];
            $lw_content = explode(',', $lw_content);
            foreach ($lw_content as $kk => $vv) {
                $lw_content[$kk] = $odds[$v['game'] . '_' . $vv];
            }
            sort($lw_content);
            $odds = $lw_content[0];
        } elseif ($v['game'] == 'ZXBZ' || $v['game'] == 'HX') {
            //自选不中,合肖
            $zxbz_content = $v['contents'];
            $zxbz_content = explode(',', $zxbz_content);
            $zxbz_count   = count($zxbz_content);
            $odds         = $odds[$v['game'] . '_' . $zxbz_count];
        } else {
            $odds = $odds[$v['game'] . '_' . $v['contents']];
        }

        $setting = S('setting');
        if ($setting['minAmount'] > $v['amount']) {
            $error['message'] = '单注投注额不能小于' . $setting['minAmount'] . '元';
            $error['status']  = 3;
            echo json_encode($error);exit(0);
        }
        if ($setting['maxAmount'] < $v['amount']) {
            $error['message'] = '单注投注额不能大于' . $setting['maxAmount'] . '元';
            $error['status']  = 3;
            echo json_encode($error);exit(0);
        }
        //查询本期投注总额
        $sumAll = M('lottery_order')->where("c_id=" . $c_id . " and c_no='" . $data['drawNumber'] . "' and m_id=" . $_SESSION['member_id'])->sum('money');
        $sumAll = $sumAll + $sum;

        if ($setting['maxPeriod'] < $sumAll) {
            $error['message'] = '每期最高投注额不能大于' . $setting['maxPeriod'] . '元';
            $error['status']  = 3;
            echo json_encode($error);exit(0);
        }

        if ($v['odds'] != $odds) {
            $error['message'] = '数据出错';
            // $error['message']=$v['game'].'_'.$v['contents'];
            $error['status'] = 3;
            echo json_encode($error);exit(0);
        }
        //if($member_info['member_money']-$member_info['member_f_money']-$sum<0){
        if ($member_info['member_money'] - $sum < 0) {
            $error['message'] = '可用余额不足';
            $error['status']  = 3;
            echo json_encode($error);exit(0);
        } else {
            $result = M('lottery_order')->addAll($insert_data);

            if ($result) {

                $betting = M('lottery_order')->where('m_id=' . $_SESSION['member_id'] . ' and status=0')->sum('money');
                if (empty($betting)) {
                    $betting = 0;
                }

                $callback['balance']           = (float) $member_info['member_money'] - $sum;
                $callback['betting']           = $betting;
                $callback['account']['bonus']  = 0;
                $callback['account']['freeze'] = $member_info['member_f_money'];
                $callback['status']            = 0;
                M('member')->where('member_id=' . $_SESSION['member_id'])->setDec('member_money', $sum); // 用户的余额较少
                //添加余额变动记录
                //······
                $insert_log['m_id']         = $_SESSION['member_id'];
                $insert_log['change_money'] = $sum;
                $insert_log['change_type']  = 1;
                $insert_log['add_time']     = time();
                $insert_log['remark']       = $c_name . '下注期号：' . $data['drawNumber'];
                M('account_log')->add($insert_log);

                echo json_encode($callback);exit(0);
            } else {
                echo json_encode($error);exit(0);
            }
        }

    }

}
